package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;

public class Filter {

    List<Integer>  array;

    public Filter(List<Integer> array) {
     this.array = array;
    }

    public List<Integer> filterEven() {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<array.size();i++){
            if(array.get(i)%2==0){
                list.add(array.get(i));
            }
        }
        return list;
    }

    public List<Integer> filterMultipleOfThree() {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<array.size();i++){
            if(array.get(i)%3==0){
                list.add(array.get(i));
            }
        }
        return list;

    }

    public List<Integer> getCommonElements(List<Integer> firstList, List<Integer> secondList) {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<firstList.size();i++){
            for (int j =0;j<secondList.size();j++){
                if (firstList.get(i).equals(secondList.get(j))) {
                    list.add(firstList.get(i));
                }
            }
        }
        return list;
    }

    public List<Integer> getDifferentElements() {
        Set<Integer> set = new HashSet<>();
        for (Integer integer : array) {
            set.add(integer);
        }
        return new ArrayList<>(set);
    }
}